package com.wjn.basic.datastruct.tree;

/**
 * 二叉树深度
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int val){
        this.val=val;
        this.left=null;
        this.right=null;
    }
    public static void main(String[] args) {
        TreeNode root=new TreeNode(0);
        TreeNode treeNode1=new TreeNode(1);
        TreeNode treeNode2=new TreeNode(2);
        TreeNode treeNode3=new TreeNode(3);
        TreeNode treeNode4=new TreeNode(4);
        TreeNode treeNode5=new TreeNode(5);
        TreeNode treeNode6=new TreeNode(7);
        root.left=treeNode1;
        root.right=treeNode2;
        treeNode1.left=treeNode3;
        treeNode1.right=treeNode4;
        treeNode2.left=treeNode5;
        treeNode3.left=treeNode6;
        System.out.println(treeDepth(root));
    }

    static int treeDepth(TreeNode root){
        if (root!=null){
            int left=treeDepth(root.left);
//            return left=left+1;
            int right=treeDepth(root.right);
            return left>right?left+1:right+1;
        }
        return 0;
    }
}




